<?php
namespace YmPhp\Admin\Http\Controllers\SiteCity;


use YmPhp\Admin\Models\Member\MemberList;
use YmPhp\Admin\Http\Repositories\SiteCityOrder;
use YmPhp\Admin\Form;
use YmPhp\Admin\Grid;
use YmPhp\Admin\Show;
use YmPhp\Admin\Http\Controllers\AdminController;

class SiteCityOrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SiteCityOrder(), function (Grid $grid) {
            $grid->quickSearch()->placeholder('搜索...');
            $grid->column('id')->sortable();
            $grid->column('stid');
            $grid->column('orderid');
            $grid->column('uid');
            $grid->column('indate')->display(function ($value) {
                return date('Y-m-d H:i:s', $value);
            });
            $grid->column('money');
            $grid->column('ratio');
            $grid->column('info')->display(function ($info) {
                $users = (new MemberList())->getD;
               return '订单标题:'.$info->subject.'<br>订单描述:'.$info->body.

                   '<br>订单金额:'.$info['baseprice'].
                   '<br>订单编号:'.$info['order_id'].
                   '<br>付款用户:'."<a href='home.php?mod=space&uid={$info['fromuid']}&do=profile' target='_blank'>$users[$fromuid]['username']</a>"

                   ;
            });
            $grid->column('reach');
            $grid->column('updated_at')->sortable();
            $grid->disableCreateButton();
            $grid->disableViewButton();

        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SiteCityOrder(), function (Show $show) {
            $show->field('id');
            $show->field('reach');
            $show->field('uid');
            $show->field('indate');
            $show->field('money');
            $show->field('ratio');
            $show->field('info');
            $show->field('stid');
            $show->field('orderid');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SiteCityOrder(), function (Form $form) {
            $form->display('id');
            $form->text('reach');
            $form->text('uid');
            $form->text('indate');
            $form->text('money');
            $form->text('ratio');
            $form->text('info');
            $form->text('stid');
            $form->text('orderid');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
